from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-07-03 14:02:17.157900
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 03, Jul, 2022
Time: 14:02:24
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.6788
Nobs: 706.000 HQIC: -50.0354
Log likelihood: 8815.85 FPE: 1.48716e-22
AIC: -50.2600 Det(Omega_mle): 1.31034e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.298683 0.057560 5.189 0.000
L1.Burgenland 0.106299 0.037826 2.810 0.005
L1.Kärnten -0.109435 0.020031 -5.463 0.000
L1.Niederösterreich 0.210628 0.079007 2.666 0.008
L1.Oberösterreich 0.104966 0.077364 1.357 0.175
L1.Salzburg 0.256880 0.040446 6.351 0.000
L1.Steiermark 0.045714 0.052693 0.868 0.386
L1.Tirol 0.109096 0.042777 2.550 0.011
L1.Vorarlberg -0.058803 0.037110 -1.585 0.113
L1.Wien 0.041357 0.068439 0.604 0.546
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.048535 0.120603 0.402 0.687
L1.Burgenland -0.034184 0.079256 -0.431 0.666
L1.Kärnten 0.041131 0.041970 0.980 0.327
L1.Niederösterreich -0.167601 0.165541 -1.012 0.311
L1.Oberösterreich 0.423547 0.162099 2.613 0.009
L1.Salzburg 0.288493 0.084746 3.404 0.001
L1.Steiermark 0.100860 0.110406 0.914 0.361
L1.Tirol 0.319110 0.089630 3.560 0.000
L1.Vorarlberg 0.027768 0.077755 0.357 0.721
L1.Wien -0.040247 0.143398 -0.281 0.779
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.187319 0.029460 6.358 0.000
L1.Burgenland 0.090120 0.019360 4.655 0.000
L1.Kärnten -0.008009 0.010252 -0.781 0.435
L1.Niederösterreich 0.264604 0.040438 6.544 0.000
L1.Oberösterreich 0.138946 0.039597 3.509 0.000
L1.Salzburg 0.045786 0.020701 2.212 0.027
L1.Steiermark 0.019649 0.026969 0.729 0.466
L1.Tirol 0.091511 0.021894 4.180 0.000
L1.Vorarlberg 0.057053 0.018994 3.004 0.003
L1.Wien 0.114326 0.035029 3.264 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.111659 0.029964 3.726 0.000
L1.Burgenland 0.045347 0.019691 2.303 0.021
L1.Kärnten -0.013691 0.010428 -1.313 0.189
L1.Niederösterreich 0.192393 0.041129 4.678 0.000
L1.Oberösterreich 0.302278 0.040274 7.506 0.000
L1.Salzburg 0.108168 0.021055 5.137 0.000
L1.Steiermark 0.104841 0.027431 3.822 0.000
L1.Tirol 0.103683 0.022269 4.656 0.000
L1.Vorarlberg 0.067448 0.019318 3.491 0.000
L1.Wien -0.022813 0.035628 -0.640 0.522
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.134632 0.054676 2.462 0.014
L1.Burgenland -0.051889 0.035931 -1.444 0.149
L1.Kärnten -0.044330 0.019027 -2.330 0.020
L1.Niederösterreich 0.156713 0.075049 2.088 0.037
L1.Oberösterreich 0.138910 0.073488 1.890 0.059
L1.Salzburg 0.286658 0.038420 7.461 0.000
L1.Steiermark 0.047926 0.050053 0.958 0.338
L1.Tirol 0.166818 0.040634 4.105 0.000
L1.Vorarlberg 0.092948 0.035251 2.637 0.008
L1.Wien 0.073899 0.065010 1.137 0.256
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.055280 0.043465 1.272 0.203
L1.Burgenland 0.037580 0.028564 1.316 0.188
L1.Kärnten 0.051097 0.015126 3.378 0.001
L1.Niederösterreich 0.217151 0.059661 3.640 0.000
L1.Oberösterreich 0.294819 0.058420 5.047 0.000
L1.Salzburg 0.047899 0.030542 1.568 0.117
L1.Steiermark 0.001892 0.039790 0.048 0.962
L1.Tirol 0.140579 0.032302 4.352 0.000
L1.Vorarlberg 0.073889 0.028023 2.637 0.008
L1.Wien 0.080688 0.051680 1.561 0.118
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.175352 0.051992 3.373 0.001
L1.Burgenland -0.002643 0.034168 -0.077 0.938
L1.Kärnten -0.062991 0.018094 -3.481 0.000
L1.Niederösterreich -0.081235 0.071366 -1.138 0.255
L1.Oberösterreich 0.194506 0.069882 2.783 0.005
L1.Salzburg 0.056392 0.036534 1.544 0.123
L1.Steiermark 0.236301 0.047596 4.965 0.000
L1.Tirol 0.497510 0.038640 12.876 0.000
L1.Vorarlberg 0.044936 0.033521 1.341 0.180
L1.Wien -0.055590 0.061820 -0.899 0.369
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.169809 0.059133 2.872 0.004
L1.Burgenland -0.012405 0.038861 -0.319 0.750
L1.Kärnten 0.063936 0.020579 3.107 0.002
L1.Niederösterreich 0.206553 0.081167 2.545 0.011
L1.Oberösterreich -0.075428 0.079480 -0.949 0.343
L1.Salzburg 0.213041 0.041552 5.127 0.000
L1.Steiermark 0.125846 0.054133 2.325 0.020
L1.Tirol 0.067117 0.043947 1.527 0.127
L1.Vorarlberg 0.119432 0.038124 3.133 0.002
L1.Wien 0.124613 0.070310 1.772 0.076
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.363218 0.034256 10.603 0.000
L1.Burgenland 0.007425 0.022512 0.330 0.742
L1.Kärnten -0.023746 0.011921 -1.992 0.046
L1.Niederösterreich 0.215834 0.047021 4.590 0.000
L1.Oberösterreich 0.205076 0.046043 4.454 0.000
L1.Salzburg 0.043406 0.024071 1.803 0.071
L1.Steiermark -0.014817 0.031360 -0.472 0.637
L1.Tirol 0.105991 0.025459 4.163 0.000
L1.Vorarlberg 0.069455 0.022086 3.145 0.002
L1.Wien 0.030494 0.040731 0.749 0.454
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037628 0.138214 0.194109 0.155835 0.115024 0.102444 0.057397 0.217930
Kärnten 0.037628 1.000000 -0.015536 0.134326 0.056055 0.095249 0.435712 -0.053306 0.093366
Niederösterreich 0.138214 -0.015536 1.000000 0.335241 0.141042 0.294191 0.092437 0.176805 0.312560
Oberösterreich 0.194109 0.134326 0.335241 1.000000 0.226909 0.324769 0.176296 0.164536 0.264153
Salzburg 0.155835 0.056055 0.141042 0.226909 1.000000 0.137954 0.116752 0.138295 0.130162
Steiermark 0.115024 0.095249 0.294191 0.324769 0.137954 1.000000 0.145631 0.129124 0.073403
Tirol 0.102444 0.435712 0.092437 0.176296 0.116752 0.145631 1.000000 0.112533 0.141873
Vorarlberg 0.057397 -0.053306 0.176805 0.164536 0.138295 0.129124 0.112533 1.000000 0.004244
Wien 0.217930 0.093366 0.312560 0.264153 0.130162 0.073403 0.141873 0.004244 1.000000